package com.zengguang.testkaoshi.controller;

import com.zengguang.testkaoshi.pojo.Questionstype;
import com.zengguang.testkaoshi.services.impl.QuestionstypeService;
import com.zengguang.testkaoshi.tool.ResponseMessage;
import com.zengguang.testkaoshi.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "questiontype")
@RestController
@CrossOrigin
public class QuestionstypeAction {
    @Autowired
    private QuestionstypeService questionstypeService;
    @ApiOperation(value = "考题类型信息查询方法")
    @RequestMapping(value = "/selectAllQuestiontype",method = RequestMethod.GET)
    public ResponseMessage selectAllQuestiontype(Questionstype questionstype) {
        Map<String, List> map=new HashMap<>();
        List<Questionstype> list=questionstypeService.selectAllQuestiontype();
        if (!list.isEmpty()){
            map.put("list",list);
            return Result.success("200",map);
        }
        return Result.error("查询失败");
    }

    @ApiOperation(value = "考题类型添加方法")
    @RequestMapping(value = "/addQuestiontype",method = RequestMethod.GET)
    public ResponseMessage addQuestiontype(Questionstype questionstype) {
        int isAdd = 0;
        //传入数据的判断
        //(1)实体对象不能为空
        if (questionstype != null) {
            //添加角色数据
            isAdd = questionstypeService.insertQuestionType(questionstype);
            if (isAdd == 1) {
                return Result.success("添加成功");
            } else {
                return Result.error("添加失败");
            }
        }
        return Result.error("添加失败");
    }

}
